﻿<div class="page-container" id="admui-pageContent">
    <div class="page animation-fade page-forms">
        <div class="page-content">
            <div class="panel">
                <div class="page-header">
                    <h1 class="page-title">战区列表</h1>
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item">
                            <a class="icon wb-home" href="javascript:;">战区管理</a>
                        </li>
                        <li class="breadcrumb-item active">战区列表</li>
                    </ol>
                </div>
                <div class="panel-body">
                    <table class="table table-bordered table-hover dataTable table-striped w-full text-nowrap" id="dataTableExample" data-plugin="dataTable">
                        <thead>
                            <tr>
                                <th>战区名称</th>
                                <th>战区所属部门</th>
                                <th>战区状态</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tfoot>
                            <tr>
                                <th>战区名称</th>
                                <th>战区所属部门</th>
                                <th>战区状态</th>
                                <th>操作</th>
                            </tr>
                        </tfoot>
                        <tbody></tbody>
                    </table>
                </div>
            </div>
        </div>
        </div>
    </div>
        <script type="text/javascript">

            $(document).ready(function () {
                $("#SpanGongSi").click();
                bang();
            });
            function bang() {
                var lang = {
                    "sProcessing": "大量处理中，请稍后...",
                    "sLengthMenu": "每页 _MENU_ 项",
                    "sZeroRecords": "没有匹配结果",
                    "sInfo": "当前显示第 _START_ 至 _END_ 项，共 _TOTAL_ 项。",
                    "sInfoEmpty": "当前显示第 0 至 0 项，共 0 项",
                    "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
                    "sInfoPostFix": "",
                    "sSearch": "搜索:",
                    "sUrl": "",
                    "sEmptyTable": "表中数据为空",
                    "sLoadingRecords": "载入中...",
                    "sInfoThousands": ",",
                    "oPaginate": {
                        "sFirst": "首页",
                        "sPrevious": "上页",
                        "sNext": "下页",
                        "sLast": "末页",
                        "sJump": "跳转"
                    },
                    "oAria": {
                        "sSortAscending": ": 以升序排列此列",
                        "sSortDescending": ": 以降序排列此列"
                    }
                };
                $("#dataTableExample").dataTable().fnDestroy();
                $('#dataTableExample').dataTable({
                    "order": [[0, "asc"]],
                    "language": lang,
                    "processing": true,
                    "serverSide": true,
                    //"bStateSave": true,//状态保持模式
                    "searching": false,//禁用搜索
                    ajax: function (data, callback, settings) {
                        //封装请求参数
                        //console.log(data);
                        var param = {};
                        param.limit = data.length;//页面显示记录条数，在页面显示每页显示多少项的时候
                        param.start = data.start;//开始的记录序号
                        param.page = (data.start / data.length) + 1;//当前页码
                        param.dir = data.order[0].dir;
                        param.column = data.order[0].column;
                        //console.log(param);

                        //ajax请求数据
                        $.ajax({
                            type: "POST",
                            url: "../ZhanQu/InitializationDataTable",
                            cache: false,  //禁用缓存
                            data: param,  //传入组装的参数
                            dataType: "json",
                            success: function (result) {
                                console.log(result);
                                //setTimeout仅为测试延迟效果
                                setTimeout(function () {
                                    //封装返回数据
                                    var returnData = {};
                                    returnData.draw = data.draw;//这里直接自行返回了draw计数器,应该由后台返回
                                    returnData.recordsTotal = result.total;//返回数据全部记录
                                    returnData.recordsFiltered = result.total;//后台不实现过滤功能，每次查询均视作全部结果
                                    returnData.data = result.data;//返回的数据列表
                                    //console.log(returnData);
                                    //调用DataTables提供的callback方法，代表数据已封装完成并传回DataTables进行渲染
                                    //此时的数据需确保正确无误，异常判断应在执行此回调前自行处理完毕"orderable" : false
                                    callback(returnData);
                                }, 200);
                            }
                        });
                    },
                    "columns": [
                        { "data": "ZhanQuMingCheng" },
                        { "data": "t_BuMenBiao.BuMenMingCheng" },
                        { "data": "ZhuangTai" },
                        { "data": null }
                    ],
                    columnDefs: [{
                        //   指定第最后一列
                        targets: -1,
                        //加下面属性 不参与排序
                        sortable: false,
                        render: function (data, type, row, meta) {
                            if (row.ZhuangTai == "启用") {
                                return '<button type="button" class="btn btn-outline btn-default" onclick="shebeiXG(' + row.Id + ')"><i class="icon wb-pencil" aria-hidden="true"></i>修改</button>   <button type="button" class="btn btn-outline btn-default" onclick="JinYong(' + row.Id + ')">禁用</button>';
                            } else {
                                return '<button type="button" class="btn btn-outline btn-default" onclick="shebeiXG(' + row.Id + ')"><i class="icon wb-pencil" aria-hidden="true"></i>修改</button>   <button type="button" class="btn btn-outline btn-default" onclick="QiYong(' + row.Id + ')">启用</button>';
                            }
                        }
                    }]
                });
            }

            function shebeiXG(id) {
                location.href = "../ZhanQu/ZhanQuUpdate?id=" + id;
            }

            function QiYong(id) {
                $.ajax({
                    type: 'post',
                    url: '../ZhanQu/QiYong',
                    async: false,
                    dataType: 'text',
                    data: { id: id },
                    success: function (date) {
                        if (date == "success") {
                            alert("更改成功!");
                            bang();
                        } else {
                            alert("失败");
                        }

                    },
                })
            }

            function JinYong(id) {
                $.ajax({
                    type: 'post',
                    url: '../ZhanQu/JinYong',
                    async: false,
                    dataType: 'text',
                    data: { id: id },
                    success: function (date) {
                        if (date == "success") {
                            alert("更改成功!");
                            bang();
                        } else {
                            alert("失败");
                        }

                    },
                })
            }

        </script>
